<?php

namespace app\api\controller;

use think\Db;

class Coupon extends Common {
    /**
     * @param $page
     * @param $pagesize
     * @return mixed
     */
    public function mycoupon($page = 1, $pagesize = 20, $state = '', $price = '', $address_id = '') {
        return $this->miss('该功能已永久关闭');
    	$where = ['user_id' => $this->member['id']];
    	if ($state !== '') {
    		$where['state'] = $state;
    	}
    	if ($price !== '') {
    		$where['minprice'] = ['<=', $price];
    		$where['price'] = ['<', $price];
    		$where['state'] = 0;
    		$where['expire_time'] = ['>', time()];
    	}
        if ($address_id !== '') {
            $where['address_id'] = $address_id;
        }
        $data = Db::name('user_coupon')
            ->where($where)
            ->order('id desc')
            ->field('user_id, data, create_time, update_time', 'filter')
            ->limit(($page - 1) * $pagesize, $pagesize)
            ->select();
        foreach ($data as $key => $value) {
            $data[$key]['minprice']    = floatval($value['minprice']);
            $data[$key]['price']       = floatval($value['price']);
            $data[$key]['expire_time'] = date('Y-m-d H:i:s', $value['expire_time']);
            if ($value['address_id']) {
                $data[$key]['addressInfo'] = Db::name('user_claim_address')->where(['id'=>$value['address_id']])->cache(60)->field('name,address')->find();
            } else {
                $data[$key]['addressInfo'] = false;
            }
        }
        return $this->pass($data);
    }
}